"use strict";
import api from "../../apis/api";
import util from "../../util/util";

/**
 * @author zhaojiuyi
 * @date 2022/9/23-22:02
 * @version 1.0.0
 */
export default {
  state: {
    adminRouter: [],
    adminInfo:{
      avatar:"",
      name: '',
      id: '',
      sex: '',
      age: '',
      jobNum: '',//工号
      title :'',//职称
      indicationDirection : '',// 研究方向
    },
    docInfo:[],
    departmentList: [],
    recordsList:[]
  },
  mutations:{
    // setAvatar(state,data){
    //   state.avatar=
    // },
    setAdminRouter (state,router) {
      state.adminRouter = router
    },
    setDepartmentList(state,info){
      state.departmentList = info
    },
    updateAdminInfo (state,info){
      state.adminInfo = info
    },
    clearAdminInfo(state){
      state.adminInfo = {}
    },
    setDocInfo(state,info) {
      state.docInfo = info
    },
    setRecordInfo(state,info){
      state.recordsList = info
    }
  },
  actions: {
    async setDocInfo({commit}) {
      const result = await api.getDocInfo()
      if (result.code ===  200){
        commit("updateAdminInfo",result.data)
      }else{
        util.errorMessage(result.msg)
      }
    },
    setSuperAdminInfo({commit}){
      const info = {
        name: "超级管理员",
      }
      console.log(info)
      commit("updateAdminInfo",info)
    },

    async getDepartmentList({commit}){
      const result = await api.getSectorList()
      if (result.code === 200){
        commit("setDepartmentList",result.data.list)
      }else{
        util.errorMessage(result.msg)
      }
    },

    async getDocInfo({commit}){
      const result = await api.getAllDocInfo()
      if (result.code === 200){
        commit("setDocInfo",result.data.list)
      }else{
        util.errorMessage(result.msg)
      }
    },

    async getRecordInfo ({commit}){
      const result = await api.getRecordInfo()
      if (result.code === 200){
        commit("setRecordInfo",result.data.list)
      }else {
        util.errorMessage(result.msg)
      }
    }
  }
}
